# include "scene.h"
# include <stdio.h>
# include <math.h>

extern short cmtrx_1dim_interpol(double *x, unsigned short nxpt, double *xipl, unsigned short nxiplpt,\
 unsigned short norder, struct cmtrx *cm, double **tempmtrx);

# define NXPT 10
# define NIPL 7
# define NORDER 5

int main()
   {
    double x[NXPT], xipl[NIPL], u[NXPT], iplval;
    short i, j;
    struct cmtrx cm;

    for(i = 0; i < NXPT; i++)
       {
        x[i] = sqrt((double)i);
        u[i] = exp(-x[i]);
       }
    for(i = 0; i < NIPL; i++) xipl[i] = x[i]+0.5;

    if( (i = cmtrx_1dim_interpol(x, NXPT, xipl, NIPL, NORDER, &cm, 0)) < 0) printf("ERROR: code = %d\n", i);
    else
      {
       printf("Interpolated values: (xipl, value)\n");
       for(i = 0; i < NIPL; i++)
        {
         for(iplval = 0, j = 0; j <= cm.iend[i]-cm.istart[i]; j++) iplval += cm.mtrx[i][j]*u[j+cm.istart[i]];
         printf("%E, %E [%E]\n", xipl[i], iplval, exp(-xipl[i]));
        }
      }

    return 0;
   }
